/*
 * Copyright (C) 2007-2012 by XDEV Software, All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 3.0 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
package xdev.ui.event;


import java.util.EventObject;

import xdev.ui.FormularComponent;
import xdev.ui.XdevFormular;
import xdev.ui.XdevFormular.WorkingState;


/**
 * Event object which contains detail information of events of a
 * {@link FormularListener}.
 * 
 * @author XDEV Software
 * 
 */
public class FormularEvent extends EventObject
{
	private FormularComponent	formularComponent;
	private Object				formularComponentEventObject;
	private WorkingState		formularWorkingState;
	

	/**
	 * Creates a new event object.
	 * <p>
	 * Used for
	 * <ul>
	 * <li> {@link FormularListener#formularModelChanged(FormularEvent)}</li>
	 * <li>
	 * {@link FormularListener#formularSavePerformed(FormularEvent)}</li>
	 * </ul>
	 * 
	 * @param source
	 *            the event's source formular
	 */
	public FormularEvent(XdevFormular source)
	{
		super(source);
	}
	

	/**
	 * Creates a new event object.
	 * <p>
	 * Used for
	 * <ul>
	 * <li>{@link FormularListener#formularComponentValueChanged(FormularEvent)}
	 * </li>
	 * </ul>
	 * 
	 * @param source
	 *            the event's source formular
	 * @param formularComponent
	 *            the changed {@link FormularComponent}
	 * @param formularComponentEventObject
	 *            the change's origin
	 * @param formularWorkingState
	 *            the current {@link WorkingState} of the underlying
	 *            <code>source</code> formular
	 * 
	 * @since 3.1
	 */
	public FormularEvent(XdevFormular source, FormularComponent formularComponent,
			Object formularComponentEventObject, WorkingState formularWorkingState)
	{
		super(source);
		
		this.formularComponent = formularComponent;
		this.formularComponentEventObject = formularComponentEventObject;
		this.formularWorkingState = formularWorkingState;
	}
	

	/**
	 * {@inheritDoc}
	 */
	@Override
	public XdevFormular getSource()
	{
		return (XdevFormular)super.getSource();
	}
	

	/**
	 * Returns the changed formular component, may be <code>null</code>.
	 * <p>
	 * Only used in
	 * {@link FormularListener#formularComponentValueChanged(FormularEvent)}
	 * 
	 * @return the changed formular component
	 * 
	 * @since 3.1
	 */
	public FormularComponent getFormularComponent()
	{
		return formularComponent;
	}
	

	/**
	 * Returns the {@link FormularComponent}-change's source event, may be
	 * <code>null</code>.
	 * <p>
	 * Only used in
	 * {@link FormularListener#formularComponentValueChanged(FormularEvent)}
	 * 
	 * @return the {@link FormularComponent}-change's source event
	 * 
	 * @since 3.1
	 */
	public Object getFormularComponentEventObject()
	{
		return formularComponentEventObject;
	}
	

	/**
	 * Returns the formular's current {@link WorkingState}, may be
	 * <code>null</code>.
	 * <p>
	 * Only used in
	 * {@link FormularListener#formularComponentValueChanged(FormularEvent)}
	 * 
	 * @return the formular's current {@link WorkingState}
	 * 
	 * @since 3.1
	 */
	public WorkingState getFormularWorkingState()
	{
		return formularWorkingState;
	}
}
